package com.gzz.orchid.context.domain.rbac.entity;

import com.gzz.orchid.context.infrastructure.definition.Action;
import com.gzz.orchid.context.infrastructure.definition.Status;
import com.gzz.orchid.context.infrastructure.persistence.entity.sys.SysModulePo;
import lombok.Data;

import java.util.Set;

/**
 * @author higmd
 */
@Data
public class ModuleDo {
    private Long id;
    /**
     * 父级模块 id parentId
     */
    private Long parentId;
    /**
     * 模块编码 code
     */
    private String code;
    /**
     * 模块名称 name
     */
    private String name;
    /**
     * 权限操作 actions
     */
    private Set<Action> actions;
    /**
     * 状态 status
     */
    private Status status;

    /**
     * 转换
     */
    public static ModuleDo convertFrom(SysModulePo po) {
        ModuleDo mdo = new ModuleDo();
        mdo.setId(po.getId());
        mdo.setParentId(po.getParentId());
        mdo.setCode(po.getCode());
        mdo.setName(po.getName());
        mdo.setActions(Action.parseSet(po.getActions()));
        mdo.setStatus(Status.parse(po.getStatus()));
        return mdo;
    }
}
